#include<bits/stdc++.h>
using namespace std;
struct num{
    int x,pos;
}nm[100007];
int t,ans=0;
bool cmp(num a,num b){
    if(a.x!=b.x)return a.x>b.x;
    return a.pos>b.pos;
}
int n,a[100007];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
            nm[i]={a[i],i};
        }
        sort(nm+1,nm+n+1,cmp);
        for(int i=1;i<=n;i++){
            if(nm[i].x==nm[i+1].x){
                ans+=nm[i].x;
                i++;
            }
        }
        cout<<ans<<'\n';
        ans=0;
    }
    return 0;
}
